/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entidades;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Damian
 */
@Entity
@Table(name = "businessman")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Businessman.findAll", query = "SELECT b FROM Businessman b"),
    @NamedQuery(name = "Businessman.findByIdBusinessman", query = "SELECT b FROM Businessman b WHERE b.businessmanPK.idBusinessman = :idBusinessman"),
    @NamedQuery(name = "Businessman.findByName", query = "SELECT b FROM Businessman b WHERE b.name = :name"),
    @NamedQuery(name = "Businessman.findBySurname", query = "SELECT b FROM Businessman b WHERE b.surname = :surname"),
    @NamedQuery(name = "Businessman.findByAddress", query = "SELECT b FROM Businessman b WHERE b.address = :address"),
    @NamedQuery(name = "Businessman.findByPhone", query = "SELECT b FROM Businessman b WHERE b.phone = :phone"),
    @NamedQuery(name = "Businessman.findByIdCity", query = "SELECT b FROM Businessman b WHERE b.businessmanPK.idCity = :idCity"),
    @NamedQuery(name = "Businessman.findByPostcode", query = "SELECT b FROM Businessman b WHERE b.postcode = :postcode"),
    @NamedQuery(name = "Businessman.findByEmail", query = "SELECT b FROM Businessman b WHERE b.email = :email"),
    @NamedQuery(name = "Businessman.findByCreationDate", query = "SELECT b FROM Businessman b WHERE b.creationDate = :creationDate"),
    @NamedQuery(name = "Businessman.findByModifDate", query = "SELECT b FROM Businessman b WHERE b.modifDate = :modifDate"),
    @NamedQuery(name = "Businessman.findByIndActive", query = "SELECT b FROM Businessman b WHERE b.indActive = :indActive")})
public class Businessman implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected BusinessmanPK businessmanPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "NAME")
    private String name;
    @Size(max = 75)
    @Column(name = "SURNAME")
    private String surname;
    @Size(max = 100)
    @Column(name = "ADDRESS")
    private String address;
    @Column(name = "PHONE")
    private Integer phone;
    @Column(name = "POSTCODE")
    private Integer postcode;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "EMAIL")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CREATION_DATE")
    @Temporal(TemporalType.DATE)
    private Date creationDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "MODIF_DATE")
    @Temporal(TemporalType.DATE)
    private Date modifDate;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 1)
    @Column(name = "IND_ACTIVE")
    private String indActive;
    @JoinColumn(name = "ID_CITY", referencedColumnName = "ID_CITY", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private City city;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "businessman")
    private Collection<Company> companyCollection;

    public Businessman() {
    }

    public Businessman(BusinessmanPK businessmanPK) {
        this.businessmanPK = businessmanPK;
    }

    public Businessman(BusinessmanPK businessmanPK, String name, String email, Date creationDate, Date modifDate, String indActive) {
        this.businessmanPK = businessmanPK;
        this.name = name;
        this.email = email;
        this.creationDate = creationDate;
        this.modifDate = modifDate;
        this.indActive = indActive;
    }

    public Businessman(int idBusinessman, int idCity) {
        this.businessmanPK = new BusinessmanPK(idBusinessman, idCity);
    }

    public BusinessmanPK getBusinessmanPK() {
        return businessmanPK;
    }

    public void setBusinessmanPK(BusinessmanPK businessmanPK) {
        this.businessmanPK = businessmanPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getPhone() {
        return phone;
    }

    public void setPhone(Integer phone) {
        this.phone = phone;
    }

    public Integer getPostcode() {
        return postcode;
    }

    public void setPostcode(Integer postcode) {
        this.postcode = postcode;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Date getModifDate() {
        return modifDate;
    }

    public void setModifDate(Date modifDate) {
        this.modifDate = modifDate;
    }

    public String getIndActive() {
        return indActive;
    }

    public void setIndActive(String indActive) {
        this.indActive = indActive;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    @XmlTransient
    public Collection<Company> getCompanyCollection() {
        return companyCollection;
    }

    public void setCompanyCollection(Collection<Company> companyCollection) {
        this.companyCollection = companyCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (businessmanPK != null ? businessmanPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Businessman)) {
            return false;
        }
        Businessman other = (Businessman) object;
        if ((this.businessmanPK == null && other.businessmanPK != null) || (this.businessmanPK != null && !this.businessmanPK.equals(other.businessmanPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entidades.Businessman[ businessmanPK=" + businessmanPK + " ]";
    }
    
}
